package samples.spring;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import samples.spring.beans.User;
import samples.spring.beans.UserHolder;

/**
 * Hello world!
 */
public class App {
    private static final Logger LOGGER = LoggerFactory.getLogger(App.class);

    public static void main(String[] args) {
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(AnnotationMain.class);

        String[] beanDefinitionNames = applicationContext.getBeanDefinitionNames();
        for (String beanDefinitionName : beanDefinitionNames) {
            LOGGER.info("beanName:{}", beanDefinitionName);
        }

        User user = applicationContext.getBean("user", User.class);
        User user1 = applicationContext.getBean("user", User.class);
        LOGGER.info("user:{} user.equals(user1)={}", user, user.equals(user1));

        User user2 = applicationContext.getBean("user2", User.class);
        User user22 = applicationContext.getBean("user2", User.class);
        LOGGER.info("user2:{}, user2.equals(user22)={}", user2, user2.equals(user22));

        UserHolder userHolder = applicationContext.getBean(UserHolder.class);
        LOGGER.info("userHolder.user: {}", userHolder.getUser());
    }
}
